﻿using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Windows.Input;

namespace TiaoTiaoCode.AutoUpdate.ServerUI.ViewModels
{
    public class MainProgramCreateViewModel : BindableBase, IDialogAware
    {

        #region 字段
        #endregion

        #region 属性

        private string programName = default!;
        private string catalog = default!;

        /// <summary>
        /// 应用程序名
        /// </summary>
        public string ProgramName
        {
            get { return programName; }
            set { SetProperty(ref programName, value); }
        }

        /// <summary>
        /// 更新文件目录
        /// </summary>
        public string Catalog
        {
            get { return catalog; }
            set { SetProperty(ref catalog, value); }
        }

        #endregion

        #region 命令

        ICommand? okCommand;

        /// <summary>
        /// 确认按钮事件
        /// </summary>
        public ICommand OkCommand => okCommand ?? (okCommand = new DelegateCommand(Ok));

        #endregion

        public MainProgramCreateViewModel()
        {

        }

        #region 命令实现

        /// <summary>
        /// 点击确定
        /// </summary>
        void Ok()
        {
            var ps = new DialogParameters();
            ps.Add("ProgramName", ProgramName);
            ps.Add("Catalog", Catalog);

            RequestClose?.Invoke(new DialogResult(ButtonResult.OK, ps));
        }

        #endregion

        #region 弹窗接口

        public string Title => "添加应用程序管理";

        public event Action<IDialogResult>? RequestClose;

        public bool CanCloseDialog()
        {
            return true;
        }

        public void OnDialogClosed()
        {

        }

        public void OnDialogOpened(IDialogParameters parameters)
        {

        }

        #endregion
    }
}
